package com.example.secondhandsysapi.Controller;

import com.example.secondhandsysapi.Entity.ShopCartInfo;
import com.example.secondhandsysapi.Service.ShopCartInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.secondhandsysapi.Vo.ShopCartGoodsInfo;
import com.example.secondhandsysapi.Entity.UserInfo;
import com.example.secondhandsysapi.Service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("shopCart")

public class ShopCartInfoController {
    @Autowired
    private ShopCartInfoService shopCartInfoService;

    @GetMapping("cart")
    public List<ShopCartGoodsInfo> getShopCartInfo1(@RequestParam Integer user_id) {
        List<ShopCartGoodsInfo> result;
        result = shopCartInfoService.getShopCartInfo1(user_id);
        return result;
    }

    //根据商品id删除掉对应的数据库里面购物车的信息
    @GetMapping("del/{goods_id}")
    private Integer deleteShopCartGoodsInfo(@RequestParam Integer goods_id,@RequestParam Integer user_id) {
        return shopCartInfoService.deleteShopCartGoodsInfo(goods_id,user_id);
    }


//        @DeleteMapping("/shopCart/deleteItems")
//        public ResponseEntity<String> deleteItems(@RequestBody List<Long> itemIds) {
//            try {
//                shopCartInfoService.deleteItems(itemIds); // 调用服务层的方法来删除商品数据
//                return new ResponseEntity<>("商品删除成功", HttpStatus.OK);
//            } catch (Exception e) {
//                return new ResponseEntity<>("删除商品失败: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
//            }
//        }
//    }

    @GetMapping("addcart")
    public Integer addCart(@RequestParam Integer user_id, @RequestParam Integer goods_id, @RequestParam Integer count) {
        Integer i = shopCartInfoService.getShopCartInfo(user_id, goods_id, count);
        return 1;
    }
}